#pragma once
#include <pthread.h>
#include "smartalloc.h"

namespace TTP::Util {

   class lockObj {
      pthread_mutex_t * lockPtr;
      bool locked;

   public:
      lockObj (pthread_mutex_t * lock) : lockPtr(lock), locked(true) 
       { pthread_mutex_lock(lockPtr); }

      ~lockObj () { if(locked) pthread_mutex_unlock(lockPtr); }

      inline void suspend() {
         pthread_mutex_unlock(lockPtr);
         locked = false;
      }

      inline void resume() {
         pthread_mutex_lock(lockPtr);
         locked = true;
      }
   };

}

